package models;

import java.io.Serializable;
import java.math.BigDecimal;

import javax.persistence.*;

import models.Transaction.Status;

import java.util.Date;

/**
 * The persistent class for the cart_item database table.
 * 
 */
@Entity
@Table(name = "CART_ITEM")
public class CartItem implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @TableGenerator(
            name = "CART_ITEM_SEQ",
            table = "SEQUENCE",
            pkColumnName = "NAME",
            pkColumnValue = "CART_ITEM_SEQ",
            valueColumnName = "CNT",
            initialValue = 10000,
            allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "CART_ITEM_SEQ")
    @Column(unique = true, nullable = false)
    private Integer id;

    private double amount;

    @Column(name = "CART_ID")
    private Integer cartId;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "CREATE_D")
    private Date createD;

    @Column(name = "LOAN_ID")
    private Integer loanId;

    private int status;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "STATUS_D")
    private Date statusD;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "UPDATE_D")
    private Date updateD;

    public CartItem() {
    }

    public CartItem(double requestAmount, Integer loanId, Integer cartId) {
        this.amount = requestAmount;
        this.loanId = loanId;
        this.cartId = cartId;
        this.createD = new Date();
        this.status = Status.PENDING.ordinal();
        this.statusD = new Date();
    }
    

    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public double getAmount() {
        return amount;
    }

    public void setAmount(double amount) {
        this.amount = amount;
    }

    public Integer getCartId() {
        return this.cartId;
    }

    public void setCartId(Integer cartId) {
        this.cartId = cartId;
    }

    public Date getCreateD() {
        return this.createD;
    }

    public void setCreateD(Date createD) {
        this.createD = createD;
    }

    public Integer getLoanId() {
        return this.loanId;
    }

    public void setLoanId(Integer loanId) {
        this.loanId = loanId;
    }

    public Status getStatus() {
        Status[] vals = Status.values();
        if (this.status > vals.length - 1 || this.status < 0)
            return null;
        return Status.values()[this.status];
    }

    public void setStatus(Status status) {
        this.status = status.ordinal();
    }

    public Date getStatusD() {
        return this.statusD;
    }

    public void setStatusD(Date statusD) {
        this.statusD = statusD;
    }

    public Date getUpdateD() {
        return this.updateD;
    }

    public void setUpdateD(Date updateD) {
        this.updateD = updateD;
    }

    public enum Status {
        PENDING, // 0
        CHECK_OUT, // 1
        EXPIRED, // 2
        REMOVED, // 3
    }

}